
--[数据]
local keys = ac.register_dzscore3('GJ',40,1)
local list = load_excel('存档数据.xlsx','捕鱼存档')
local items = {}
for i,info in ipairs(list) do
    local name = info['名称']
    info.tip = ("|cffff9900属性：|r|n%s'ex_tip'"):format(info['属性'])
    
    --解析属性
    info.bdata1 = info.data1
    info.bdata2 = info.data2
    info.bdata3 = info.data3
    info['属性1'] = cd_unpack_attrs(info['1-20级'],'data')
    info['属性2'] = cd_unpack_attrs(info['21-40级'],'data')
    info['属性3'] = cd_unpack_attrs(info['41-50级'],'data')
    info.code = keys[i]
    info.name = name
    info.level = 0
    info.sx_tip = function(self,level)
        local level = level or self.level or 0
        self.data1 = self.bdata1 * level
        self.data2 = self.bdata2 * math.max(level-20,0)
        self.data3 = self.bdata3 * math.max(level-40,0)
        local tip = self['1-20级']
        if level>20 then
            tip = ('%s|n%s'):format(tip,self['21-40级'])
        end
        if level>40 then
            tip = ('%s|n%s'):format(tip,self['41-50级'])
        end
        return format_obj(self,tip)
    end
    info.tip = function(self,level)
        local level = self.level or 0
        local jf = 100 + (level * 20)
        local tip1 = self:sx_tip(level)
        if level<50 then
            tip1 = ('升级积分：%s|n|n属性：|n%s|n|n下一级属性:|n%s'):format(jf,tip1,self:sx_tip(level+1))
        else
            tip1 = ('属性：|n%s|n|n已满级'):format(tip1)
        end
        return tip1
    end

    items[name] = info

end


ac['捕鱼存档'] = list

ac.game:event '玩家-选择英雄完毕'(function(_,player)
    player:notify('玩家-加载捕鱼属性',player)
end)

ac.game:event '云消息-获取捕鱼积分'(function(_,player,point)
    player:set_data('捕鱼积分',point)
    player:notify('玩家-加载捕鱼属性',player)
end)

ac.game:event '玩家-加载捕鱼属性'(function(_,player)
    local hero = player.hero
    local point = player:get_data('捕鱼积分') or 0
    local used = 0
    local sums = {}
    local count = player:get_data('捕鱼加载次数',0)
    player:set_data('捕鱼加载次数',count + 1)
    if count<2 then
        return
    end
    for _,info in ipairs(list) do
        local lv = player:dz_get(info.code)
        if open then
            for a=1,lv do
                local jf = 100 + (a - 1) * 20
                if point>=jf then
                    point = point - jf
                    used = used + jf
                else
                    lv = 0
                    player:dz_set(info.code,0)
                    break
                end
            end
        end
        sums[info.name] = lv
        if lv>0 then
            for a,da in ipairs(info['属性1']) do
                local key1 = da[1]
                local key2 = da[2]
                local num = info[key2]
                hero:add(key1, num * lv)
            end
            if lv>20 then
                for a,da in ipairs(info['属性2']) do
                    local key1 = da[1]
                    local key2 = da[2]
                    local num = info[key2]
                    hero:add(key1,num * (lv - 20))
                end
            end
            if lv>40 then
                for a,da in ipairs(info['属性3']) do
                    local key1 = da[1]
                    local key2 = da[2]
                    local num = info[key2]
                    hero:add(key1,num * (lv - 40))
                end
            end
        end
        if player:is_self() then
            info.level = lv
            info.open = lv>0
        end
    end
    
    player:set_data('捕鱼积分-使用',used)
    player:set_data('捕鱼积分-等级',sums)
end)


ac.game:event '玩家-升级捕鱼存档'(function(_,player,name,count,hide)
    local point = player:get_data('捕鱼积分') or 0
    local used = player:get_data('捕鱼积分-使用') or 0
    local sums = player:get_data('捕鱼积分-等级') or {}
    local count = count or 1
    local info = items[name]
    local level = sums[name] or 0
    if info==nil or info==nil then
        return
    end
    point = point - used
    for a=1,count do
        local jf = 100 + (level * 20)
        if point>=jf and level<50 then
            point = point - jf
            used = used + jf
            level = level + 1
        else
            break
        end
    end
    if player:is_self() then
        info.level = level
        info.open = level>0
    end
    --保存数据
    sums[name] = level
    player:dz_set(info.code,level)
    player:set_data('捕鱼积分-使用',used)
    player:set_data('捕鱼积分-等级',sums)
end)



ac.sync:event '同步-升级捕鱼存档'(function(_,player,name,count)
    if player:get_data('捕鱼积分')==nil then
        return
    end
    player:notify('玩家-升级捕鱼存档',player,name,count)
end)


ac.sync:event '同步-重置捕鱼存档'(function(_,player,name,count)
    player:get_data('捕鱼积分-使用',0)
    player:get_data('捕鱼积分-等级',{})
    for _,info in ipairs(list) do
        player:dz_set(info.code,0)
        if player:is_self() then
            info.level = 0
            info.open = false
        end
    end
end)


ac.game:event '游戏-挂机模式'(function(_,player)
    ac.each_player(function(player)
        player:send_cloud('游戏难度','挂机模式')
    end)
end)